<?php
include("check.php");
/*include("check2.php");*/
include_once("../function.php");
include_once("../class/bonus_class.php");
include_once("../class/member_class.php");
include_once("../class/ulevel_class.php");
header("Content-Type: text/html;charset=utf-8");
session_start();
$us=getMemberbyID($_SESSION['ID']);
$_bonus_cl=new bonus_class();
$mey=$us['mey'];
$gwb=$us['gwb'];
if ($_POST['submit']){
    $member_cl=new member_class();
    $ulevel_cl=new ulevel_class();
    $_uil=$ulevel_cl->getulevelbyulevel($us['ulevel']);
    $jine=$_POST['jine'];
    $txlx = $_POST['txlx'];
    if($txlx==1){
        $sy=$us['mey']-$jine;
    }else{
        $sy=$us['gwb']-$jine;
    }
    if($sy>=0){
        $sum=getfutou($us['id']);
        if($sum<55000) {
            $yejijine = $jine / 1.1;
            $ulevelup['uid'] = $_SESSION['ID'];
            $ulevelup['nickname'] = $us['nickname'];
            $ulevelup['username'] = $us['username'];
            $ulevelup['ylevel'] = $sus['ulevel'];
            $ulevelup['uplevel'] = $_POST['uplv'];
            $ulevelup['bdid'] = $us['bdid'];
            $ulevelup['bdname'] = $us['bdname'];
            $ulevelup['sid'] = $yejijine * 2;
            $ulevelup['snickname'] = $us['nickname'];
            $ulevelup['susername'] = $us['username'];
            $ulevelup['udate'] = now();
            $ulevelup['issh'] = 0;
            $ulevelup['cha'] = $jine;
            add_insert_cl('futou', $ulevelup);
            if ($txlx == 1) {
                $us_update['mey'] = $us['mey'] - $jine;
            } else {
                $us_update['gwb'] = $us['gwb'] - $jine;
            }
            if($us['ulevel']==2){
                $us_update['cfxf'] = $us['cfxf'] + $yejijine * $_uil['yl10'] / 100;
            }
            $us_update['futou'] = $us['futou'] + $yejijine * 2;
            edit_update_cl('member', $us_update, $us['id']);
            $member_cl->addArea($us['id'], $us['treeplace'], $yejijine);
            $_bonus_cl->b3bonus($us['id'], $us['nickname'], $us['ppath'], $us['plevel'], $yejijine);
            $_bonus_cl->b0bonus();
            //$_bonus_cl->fwzx();
            echo "<script language=javascript>alert('复投完成.');window.location.href='?'</script>";
        }else{
            echo "<script language=javascript>alert('复投金额已超出.');window.location.href='?'</script>";
        }
    }else{
        echo "<script language=javascript>alert('余额不足.');window.location.href='?'</script>";
    }



}
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link href="css/table.css" rel="stylesheet" type="text/css">
    <link rel="stylesheet" type="text/css" href="css/style.css" />
    <link rel="stylesheet" type="text/css" href="./awesome/css/font-awesome.min.css"/>
    <link href="css/style1.css" rel="stylesheet" type="text/css">
    <link rel="stylesheet" href="./he/jquery.ui.autocomplete.css">
    <script type="text/javascript" src="./js/jquery.min.js"></script>
    <script src="./js/style.js" type="text/javascript" charset="utf-8"></script>
    <title>复投申请</title>
    <script language="javascript">
        <!--
        function CheckForm() {
            jine=document.form1.jine.value;
            Txlx=document.form1.txlx.value;
            Level=document.form1.level.value;

            if(jine.length == 0){
                alert("温馨提示:\n请输入复投金额.");
                document.form1.jine.focus();
                return false;
            }
            if(Txlx==1 && jine%550!=0){
                alert("奖励积分复投金额最小倍数为550");
                document.form1.jine.focus();
                return false;
            }


            if(Level==1){
                if(jine%3300!=0&&Txlx==2){
                    if(jine%11000!=0&&Txlx==2){
                         alert("金种子复投金额最小倍数为11000或3300");
                   /*     alert("请输入正确的投资金额");*/
                        document.form1.jine.focus();
                        return false;
                    }
                }
            }else{
                if(jine%11000!=0&&Txlx==2){
                    alert("金种子复投金额最小倍数为11000");
                    document.form1.jine.focus();
                    return false;
                }
            }
    /*        if(Level==1){
                if(jine%3300!=0&&Txlx==2){
                    alert("金种子复投金额最小倍数为3300");
                    document.form1.jine.focus();
                    return false;
                }
            }else{
                if(jine%11000!=0&&Txlx==2){
                    alert("金种子复投金额最小倍数为11000");
                    document.form1.jine.focus();
                    return false;
                }
            }*/

        }
        function showlist() {

            UserTel=document.form1.txlx.value;

            if (UserTel == "1") {
                document.getElementById('zt1').style.display = "";
                document.getElementById('zt2').style.display = "none";
            }
            else if (UserTel == "2") {
                document.getElementById('zt1').style.display = "none";
                document.getElementById('zt2').style.display = "";
            }
        }
        /*function checknickname(lx)
         {
         var iframe = document.getElementById("iframe");
         var user =  document.getElementById("nickname");
         iframe.src= "checknickname.php?lx="+lx+"&nickname="+user.value;
         }*/

        -->

    </script>
</head>
<body>
<?php
$title="复投申请";
include_once("./public/header_nav.html");
?>
<iframe name="iframe" id="iframe" width="0" height="0" src="about:blank" style="display:none"></iframe>
<form name="form1" method="post" action="?" onSubmit="return CheckForm();">
    <table  width="100%" cellpadding="3" cellspacing="1" border="0" align="center" class="table1">
        <tr id="zt1" >
            <td width="46%" height="22" align="right">奖励积分：</td>
            <td width="54%" align="left"><?=$mey?></td>
        </tr>
        <tr id="zt2" style="display: none">
            <td width="46%" height="22" align="right">金种子：</td>
            <td width="54%" align="left"><?=$gwb?></td>
        </tr>
        <tr>
            <td width="46%" height="22" align="right">复投类型：</td>
            <td width="54%" align="left">
                <select name="txlx" id="txlx" onchange="showlist()">
                    <option value="1">奖励积分</option>
                    <option value="2">金种子</option>
                </select></td>
        </tr>
        <tr>
            <td width="46" height="22" align="right">复投金额</td>
            <td><input name="jine" type="text" id="jine" size="10" maxlength="10"></td>
            <input name="level" type="hidden" value="<?=$us['level']?>">
        </tr>
    </table>
    <table align="center" class="ziti" width="100%">
        <tr>
            <td align="center"><input name="submit" id="submit" type="submit" class="button_green" value="确定复投" <!--onClick="javascript:return confirm('您确认复投吗？');-->"></td>
        </tr>
    </table>
    <br>
    <table width="100%" cellpadding="3" cellspacing="1" border="0" align="center" class="table1">
        <tr>
            <td height="20" colspan="8" align="center"> 申 请 记 录</td>
        </tr>
        <tr>

            <td align="center">会员编号</td>
            <td align="center">会员姓名</td>
            <!--        <td align="center">原级别</td>-->
            <!--        <td align="center">申请级别</td>-->
            <td align="center">复投金额</td>
            <td align="center">申请时间</td>
            <td align="center">操作人编号</td>
            <td align="center">操作人姓名</td>
            <td style="display:none" align="center">审核状态</td>
        </tr>
        <?php
        $pagesize = 10; //设置每页记录数
        $sql = "SELECT * FROM `futou` WHERE uid=".$_SESSION['ID']." or sid=".$_SESSION['ID']."";
        if($query = mysql_query($sql)){
            $sum = mysql_num_rows($query); //计算总记录数
        }else{
            $sum=0;
        }
        if($sum % $pagesize == 0) //计算总页数
            $total = (int)($sum/$pagesize);
        else
            $total = (int)($sum/$pagesize) + 1;
        if (isset($_GET['page'])) //获得页码
        {
            $p = (int)$_GET['page'];
        }
        else
        {
            $p = 1;
        }
        if ($p>$total){
            $p=$total;
        }
        $start = $pagesize * ($p - 1); //计算起始记录
        $sql = "SELECT * FROM `futou` WHERE uid=".$_SESSION['ID']." or sid=".$_SESSION['ID']." order by id desc limit ".$start.",".$pagesize;
        if($query = mysql_query($sql)){
            while ($row=mysql_fetch_array($query)){
                $yul=ulevel($row['ylevel']);
                $uul=ulevel($row['uplevel']);
                ?>
                <tr>

                    <td align="center"><?=$row['snickname']?></td>
                    <td align="center"><?=$row['susername']?></td>
                    <!--        <td align="center"><?/*=$yul['lvname']*/?></td>
        <td align="center"><?/*=$uul['lvname']*/?></td>-->
                    <td align="center"><?=$row['cha']?></td>
                    <td align="center"><?=$row['udate']?></td>
                    <td align="center"><?=$row['nickname']?></td>
                    <td align="center"><?=$row['username']?></td>
                    <td style="display:none"  align="center"><?php if ($row['issh']==1){?>通过审核<?php }else{?> <font color="#FF0000">未审核</font><?php }?></td>
                </tr>
                <?php
            }
        }
        ?>
    </table>
    <table width="100%" border="0" class="ziti">
        <tr>
            <td align="left">&nbsp;</td>
            <td  style="padding-top: 0.4rem" align="right"><?php echo fenye($p,$pagesize,$sum,$total,$cx)?></td>
        </tr>
    </table>
</form>
<?php include_once ("public/footer_nav.html")?>
</body>
</html>